const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
    if (xhr.readyState === XMLHttpRequest.DONE) {

        if (xhr.status >= 200 && xhr.status < 300) {

            // success
        }

    } else if (xhr.readyState === XMLHttpRequest.OPENED) {
        xhr.setRequestHeader('content-type', 'application/json');
    }
}
xhr.onerror = function (){

}
xhr.open('GET', 'http://localhost')
xhr.send();